<template>
	<view class="footer">
		<view class="tabbar">
			<view class="action-item" @click="backHome">
				<u-icon name="home-fill" color="#666" size="22"></u-icon>
				<text class="text">首页</text>
			</view>
			<view class="action-item" @click="backAsk">
				<u-icon name="chat-fill" color="#666" size="24"></u-icon>
				<text class="text">咨询</text>
			</view>
			<view class="action-item floating-button" @click="navAdd">
				<text class="text">{{this.text}}</text> <!-- {{this.localId}} -->
			</view>
			<view class="action-item" @click="backBbs">
				<u-icon name="weixin-fill" color="#666" size="24"></u-icon>
				<text class="text">论坛</text>
			</view>
			<view class="action-item" @click="backMine">
				<u-icon name="account-fill" color="#666" size="24"></u-icon>
				<text class="text">我的</text>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		name: 'Footer',
		props: {
			type: {
				type: String,
				required: true
			},
			id: {
				type: [String, Number],
				required: true
			}
		},
		data() {
			return {
				//searchKey: ''
				localType: '',
				localId: '',
				text:'问'
			};
		},
		methods: {
			backHome() {
				// uni.switchTab({
				// 	url: '/pages/index'
				// });
				const url = `/pages/index`;
				this.$tab.switchTab(url);
			},
			backMine() {
				// uni.switchTab({
				// 	url: '/pages/mine/index'
				// });
				const url = `/pages/mine/index`;
				//this.$tab.redirectTo(url);
				this.$tab.switchTab(url);
			},
			backAsk() {
				// uni.switchTab({
				// 	url: '/pages/ask/list'
				// });
				const url = `/pages/ask/list`;
				this.$tab.redirectTo(url);
			},
			backBbs() {
				// uni.switchTab({
				// 	url: '/pages/bbs/index'
				// });
				const url = `/pages/bbs/bbs`;
				this.$tab.switchTab(url);
			},
			navAdd() {
				// 根据类型进行不同的页面跳转
				if (this.localType === 'ask') {
					// uni.navigateTo({
					//   url: `/pages/ask/ask?id=${this.localId}`
					// });
					const url = `/pages/ask/ask?id=${this.localId}`;
					this.$tab.navigateTo(url);
				} else if (this.localType === 'answer') {
					// uni.navigateTo({
					//   url: `/pages/answer/answer?id=${this.localId}`
					// });
					const url = `/pages/answer/answer?id=${this.localId}`;
					this.$tab.navigateTo(url);
					//this.$tab.redirectTo(url);
				} else {
					console.warn('未知类型:', this.localType);
				}
			}
		},
		created() {
			// 将传递过来的参数保存到本地 data 中
			this.localType = this.type;
			this.localId = this.id;
			if(this.localType=='ask'){
				this.text='问'
			}else{
				this.text='答';
			}
		},
		watch: {
			type(newVal) {
				console.log('type changed:', newVal);
				// 根据 type 的新值执行其他逻辑
				this.localType = newVal;

			},
			id(newVal) {
				console.log('id changed:', newVal);
				// 根据 id 的新值执行其他逻辑
				this.localId = newVal;
			}
		}
	};
</script>

<style scoped>
	.footer {
		background-color: #eee;
		padding: 10px;
		position: fixed;
		/* 固定在底部 */
		bottom: 0;
		width: 100%;
		/* 充满整个宽度 */
		display: flex;
		justify-content: center;
	}

	.tabbar {
		display: flex;
		justify-content: space-around;
		align-items: center;
		width: 100%;
		/* 使 tabbar 充满宽度 */
		max-width: 600px;
		/* 可选: 设置最大宽度 */
	}

	.tabbar .action-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 12px;
		color: #333;
		cursor: pointer;
	}

	.tabbar .icon-home,
	.tabbar .icon-mine {
		font-size: 24px;
		color: #333;
	}

	.floating-button {
		width: 60px;
		height: 60px;
		background-color: #6db87b;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
		font-size: 36px;
		cursor: pointer;
		margin-top: -30px;
		/* 调整按钮位置使其位于tabbar上方 */
	}

	.floating-button .text {
		color: #fff;
		font-size: 28px;
	}
</style>